package com.shop.controller;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("go")
public class ForwardController {
    //localhost:8088/boot/go/from
    @GetMapping("from")
    public String from(HttpServletRequest request){
        System.out.println("from....");
        request.setAttribute("username","admin");
        return "forward:to";
    }
    @ResponseBody
    @GetMapping("to")
    public String to(HttpServletRequest request){
        String username=(String)request.getAttribute("username");
        System.out.println("to...");
        return "to"+username;
    }
    @GetMapping("come")
    public String com(HttpServletRequest request){
        //将数据放入到request作用域中
        request.setAttribute("username","admin");
        return "redirect:to";
    }
}
